package com.itrip.controller;

import com.itrip.document.Hotel;
import com.itrip.dto.HotelDTO;
import com.itrip.dto.ResponseDTO;
import com.itrip.dto.RoomDTO;
import com.itrip.service.HotelService;
import com.itrip.vo.HotelSelectVo;
import io.swagger.annotations.*;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Api(tags = "酒店接口")
@RestController
public class HotelController {
    @Resource
    private HotelService hotelService;

    @ApiOperation("查询所有酒店")
    @GetMapping("/view/getAllHotel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNow",value = "当前页数",example = "1"),
            @ApiImplicitParam(name = "pageSize",value = "页面大小",example = "6"),
            @ApiImplicitParam(name = "token",value = "登录令牌",paramType = "header",dataType = "String")
    })
    public ResponseDTO getAllHotel(Integer pageNow,Integer pageSize){
        int start =(pageNow-1)*pageSize;
        List<HotelDTO> hotelDTO= hotelService.getAllHotel(start,pageSize);
        return new ResponseDTO(100,"酒店数据查询成功",hotelDTO);
    }

    @ApiOperation("查询酒店数量")
    @GetMapping("/getHotelNum")
    public ResponseDTO getHotelNum(){

        int count= hotelService.getHotelNum();
        return new ResponseDTO(100,"酒店数据查询成功",count);
    }


    @ApiOperation("查询酒店的房间")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hotelId",value = "酒店Id",example = "1",required = true)
    })
    @GetMapping("/selectHotelRoom")
    public ResponseDTO selectHotelRoom(@RequestParam("hotelId") int hotelId){
        //获取这个酒店的房间List
        List<RoomDTO> roomDTOList=hotelService.selectHotelRoom(hotelId);
        return new ResponseDTO(100,"查询酒店房间成功",roomDTOList);
    }





    @ApiOperation("solr查询酒店")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "登录令牌",paramType = "header",dataType = "String")
    })
    @PostMapping("/selectHotelBySolr")
    public ResponseDTO selectHotelBySolr(HotelSelectVo hotelSelectVo) throws IOException, SolrServerException {
        List<Hotel> hotels = hotelService.selectHotelBySolr(hotelSelectVo);
        return new ResponseDTO(100,"查询成功",hotels);
    }

}
